home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94b.txt / 000067_icon-group-sender _Mon Sep 26 14:02:29 1994.msg < prev    next >
Internet Message Format  |  1995-02-09  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Mon, 26 Sep 1994 08:48:09 MST
  2. To: icon-group-l@cs.arizona.edu
  3. Date: Mon, 26 Sep 1994 14:02:29 GMT
  4. From: goer@quads.uchicago.edu (Richard L. Goerwitz)
  5. Message-Id: <1994Sep26.140229.22474@midway.uchicago.edu>
  6. Organization: University of Chicago
  7. Sender: icon-group-request@cs.arizona.edu
  8. References: <940926100948@ibm3090.bham.ac.uk>
  9. Reply-To: goer@midway.uchicago.edu
  10. Subject: Re: sort() but descending?
  11. Errors-To: icon-group-errors@cs.arizona.edu
  12.  
  13. Gabriel Landini writes:
  14. >
  15. >I would like to sort that list from more frequent to less frequent, but I
  16. >cannot find the way to do it. Any ideas?
  17. >Does the sort(0 and sortf() only sort in ascending order?
  18. >thanks
  19.  
  20. The sort order is predefined, in ascending order.  Presumably the reason
  21. for this so that we don't have sorted lists floating around with different
  22. sort orders.  One size fits all.
  23.  
  24. Of course it's easy enough to use elements from sorted lists in any order.
  25. In Icon you have ready access to any element within a list.  E.g. for as-
  26. cending order:
  27.  
  28.     l := sort(x)
  29.     every element := !l do {
  30.         do something with element
  31.         ...
  32.  
  33. Or, if you don't need to keep l around -
  34.  
  35.     every element := !sort(x) do {
  36.         do something with element
  37.         ...
  38.  
  39. For descending order:
  40.  
  41.     l := sort(x)
  42.     every i := *x to 1 by -1 do {
  43.         do something with x[i]
  44.         ...
  45.  
  46. Does this seem to help any?
  47.  
  48. -- 
  49.  
  50.    -Richard L. Goerwitz              goer%midway@uchicago.bitnet
  51.    goer@midway.uchicago.edu          rutgers!oddjob!ellis!goer
  52.